{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0.30644169 0.7048497  0.72862177]\n",
      "          X1        X2        X3\n",
      "0   0.991621  0.446665  0.655971\n",
      "1   0.193307  0.180080  0.803941\n",
      "2   0.174480  0.853910  0.931141\n",
      "3   0.679380  0.276404  0.530853\n",
      "4   0.870960  0.482819  0.815908\n",
      "5   0.955236  0.854171  0.302721\n",
      "6   0.577082  0.553999  0.406951\n",
      "7   0.775148  0.182846  0.343661\n",
      "8   0.708145  0.539966  0.754804\n",
      "9   0.031900  0.972085  0.368518\n",
      "10  0.476423  0.641487  0.615530\n",
      "11  0.165364  0.363277  0.868067\n",
      "12  0.364204  0.010102  0.686292\n",
      "13  0.740016  0.723434  0.274037\n",
      "14  0.759338  0.912989  0.283190\n",
      "15  0.363442  0.936685  0.344851\n",
      "16  0.360767  0.510175  0.703559\n",
      "17  0.130752  0.632064  0.559690\n",
      "18  0.767074  0.961552  0.756770\n",
      "19  0.467850  0.026207  0.910734\n",
      "20  0.140191  0.866004  0.677850\n",
      "21  0.577517  0.112683  0.879753\n",
      "22  0.223391  0.368965  0.475984\n",
      "23  0.261140  0.999980  0.460451\n",
      "24  0.608837  0.095907  0.782145\n",
      "0     0.998345\n",
      "1     0.861059\n",
      "2     1.162735\n",
      "3     0.884578\n",
      "4     1.031530\n",
      "5     1.100595\n",
      "6     0.973259\n",
      "7     0.821015\n",
      "8     1.037775\n",
      "9     1.099085\n",
      "10    1.036236\n",
      "11    0.948769\n",
      "12    0.787946\n",
      "13    1.027237\n",
      "14    1.106864\n",
      "15    1.102890\n",
      "16    0.994705\n",
      "17    1.001750\n",
      "18    1.214616\n",
      "19    0.837410\n",
      "20    1.118596\n",
      "21    0.875655\n",
      "22    0.883724\n",
      "23    1.143542\n",
      "24    0.854186\n",
      "Name: Y, dtype: float64\n"
     ]
    }
   ],
   "source": [
    "\n",
    "from lib2to3.pgen2.token import NAME\n",
    "from pickle import NONE\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "from numpy.linalg import inv  # 矩阵求逆\n",
    "from numpy import dot  # 矩阵点乘\n",
    " \n",
    " \n",
    "dataset = pd.read_csv(\"D:\\AppData\\工作\\data.csv\",names=['X1','X2','X3','Y'])  # 读入数据\n",
    "X = dataset.iloc[:, 0: 3]  # x为所有行，1到3列\n",
    "Y = dataset.iloc[:, 3]  # y为所有行，第4列\n",
    "a = dot(dot(inv(np.dot(X.T, X)), X.T), Y)  # 最小二乘法求解公式\n",
    "print(a)\n",
    "print(X)\n",
    "print(Y)\n",
    "#答案：[0.30644169 0.7048497  0.72862177]；"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.9.13 ('robomaster')",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "d488e29a69396f7b3bc12ae9eed63c8bfcf92fd19c83d1949b0efc33e68bbd32"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
